home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: netcom.com!marnold
- From: marnold@netcom.com (Matt Arnold)
- Subject: Re: int::~int()
- Message-ID: <marnoldDpuDu9.D7s@netcom.com>
- Organization: NETCOM On-line Communication Services (408 261-4700 guest)
- References: <317083F7.116E@public.sta.net.cn>
- Date: Sun, 14 Apr 1996 07:51:45 GMT
- Sender: marnold@netcom13.netcom.com
-
- Xu Yifeng <jafd@public.sta.net.cn> writes:
-
- >Hi everybody,
-
- >can your compiler compile following program?
-
- >//------------------------
- >void main()
- >{
- > int i = 0;
-
- > i.int::~int();
- >}
- >//------------------------
-
- >is it a legal C++ program?
-
- It's supposed to be, but most C++ compiler's will not compile it.
-
- In fact, this exact sitution is encountered in the Standard Template
- Library (STL), which contains the following template function...
-
- template <class T>
- inline void destroy(T* pointer) {
- pointer->~T();
- }
-
- ...which is supposed to be used to destroy anything, including an
- instance of an int, just like your sample code wants to.
-
- To make STL work with current compilers, you'll find it also contains
- work-around versions of destroy(). There's one specifically for int,
- and it looks like this...
-
- inline void destroy(int*) {}
-
- ...which is what the template version is supposed to do; nothing. STL
- contains about 50 or so of these specific versions of destroy() (for
- ints, chars, floats, etc.).
-
- You sample code is legal as far as the language goes, but probably
- not as far as your compiler is concerned. Mine, Borland C++ 4.52,
- will not compile it either. However, I think Borland C++ 5.0 will.
-
- Regards,
- -------------------------------------------------------------------------
- Matt Arnold | | ||| | |||| | | | || ||
- marnold@netcom.com | | ||| | |||| | | | || ||
- Boston, MA | 0 | ||| | |||| | | | || ||
- 617.389.7384 (h) 617.576.2760 (w) | | ||| | |||| | | | || ||
- C++, MIDI, Win32/95 developer | | ||| 4 3 1 0 8 3 || ||
- -------------------------------------------------------------------------
-